import service from '@/utils/request';

interface ResponseData<T = any> {
    code: number;
    message: string;
    data: T;
}

// GET 请求
export async function get<T>(url: string, params?: object): Promise<T> {
    const response: ResponseData<T> = await service.get(url, { params });
    return response.data;
}

// POST 请求
export async function post<T>(url: string, data?: object): Promise<T> {
    const response: ResponseData<T> = await service.post(url, data);
    return response.data;
}

// PUT 请求
export async function put<T>(url: string, data?: object): Promise<T> {
    const response: ResponseData<T> = await service.put(url, data);
    return response.data;
}

// DELETE 请求
export async function del<T>(url: string, params?: object): Promise<T> {
    const response: ResponseData<T> = await service.delete(url, { params });
    return response.data;
}

// PATCH 请求（可选）
export async function patch<T>(url: string, data?: object): Promise<T> {
    const response: ResponseData<T> = await service.patch(url, data);
    return response.data;
}
